{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "00ea909a-5f34-4bfb-b175-e3f8048b5c52",
   "metadata": {},
   "source": [
    "https://leetcode.com/problems/reorder-list\n",
    "\n",
    "\n",
    "Runtime: 88 ms, faster than 87.38% of Python3 online submissions for Reorder List.\n",
    "Memory Usage: 23.3 MB, less than 47.25% of Python3 online submissions for Reorder List.\n",
    "\n",
    "\n",
    "\n",
    "```python\n",
    "# Definition for singly-linked list.\n",
    "# class ListNode:\n",
    "#     def __init__(self, val=0, next=None):\n",
    "#         self.val = val\n",
    "#         self.next = next\n",
    "class Solution:\n",
    "    def reorderList(self, head: ListNode) -> None:\n",
    "        \"\"\"\n",
    "        Do not return anything, modify head in-place instead.\n",
    "        \"\"\"\n",
    "        #6:59\n",
    "        l = []\n",
    "        node = head\n",
    "        while node:\n",
    "            l.append(node)\n",
    "            node = node.next\n",
    "        new_l = []\n",
    "        length = len(l)\n",
    "        for index, node in enumerate(l):\n",
    "            #print(index, length-index-1)\n",
    "            if (index > length-index-1):\n",
    "                break\n",
    "            if (index == length-index-1):\n",
    "                new_l.append(l[index])\n",
    "                break\n",
    "            new_l.append(l[index])\n",
    "            new_l.append(l[length-index-1])\n",
    "        for index, node in enumerate(new_l):\n",
    "            if index == len(new_l)-1:\n",
    "                node.next = None\n",
    "            else:\n",
    "                node.next = new_l[index+1]\n",
    "        return None\n",
    "        #7:07\n",
    "```"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4501afb4-99c9-4f04-a5a2-fa2222b4ba2b",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
